package com.praveen.reminder;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;

import android.app.IntentService;
import android.content.Intent;

@SuppressWarnings("unused")
public class ReminderDataSaveService extends IntentService {
	private final static String LOGTAG = "ReminderDataService";
	
	public ReminderDataSaveService() {
		super("ReminderDataSaveService");
	}

	@Override
	protected void onHandleIntent(Intent arg0) {
		ReminderApplication app = (ReminderApplication)getApplication();
		XMLFileManager fmngr = app.getFileManager();
		try {
			FileOutputStream fos = openFileOutput("appData.xml", MODE_WORLD_READABLE);
			TransformerFactory transformerFactory = TransformerFactory.newInstance();
			Transformer transformer = transformerFactory.newTransformer();
			DOMSource source = new DOMSource(fmngr.getDocument());
			StreamResult result =  new StreamResult(fos);
			transformer.transform(source, result);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (TransformerConfigurationException e) {
			e.printStackTrace();
		} catch (TransformerException e) {
			e.printStackTrace();
		} 
	}

}
